<template>
  <div id="app">
      <div id="nav" v-if="!$route.meta.showNav">      
        <el-menu
              :default-active="activeIndex"
              class="el-menu-demo"
              mode="horizontal"
              
              background-color="#545c64"
              text-color="#fff"
              active-text-color="#ffd04b"
              :unique-opened="true"  
              menu-trigger=click
              :router=true>
            
              <el-submenu index="1">
                  <template slot="title">用户管理
                  <el-badge :value="needAuditUserAndParkingSpaceNo" class="item">
                  </el-badge> 
                  
                  </template>          
                  <el-menu-item index="/auditUser">账号审核
                    <el-badge :value="needAuditUserNo" class="item">
                  </el-badge> 
                  </el-menu-item>
                  <el-menu-item index="/auditParkingSpace">停车位审核
                    <el-badge :value="needAuditParkingNo" class="item">
                  </el-badge> 
                  </el-menu-item>
                  <el-menu-item index="/updateParkingSpaceGetPart">停车位提成比例调整</el-menu-item>
                  <el-menu-item index="/auditRecordQuery">审核记录查询</el-menu-item>
                  <!-- <el-submenu index="1-4">
                  <template slot="title">选项4</template>
                  <el-menu-item index="1-4-1">选项1</el-menu-item>
                  <el-menu-item index="1-4-2">选项2</el-menu-item>
                  <el-menu-item index="1-4-3">选项3</el-menu-item>
                  </el-submenu> -->
              </el-submenu>  
            <el-submenu index="2">
                <template slot="title">物业方管理</template>
                <el-menu-item index="/propertyManager">物业账号注册</el-menu-item>
                
              
            </el-submenu>
        
            <el-submenu index="3">
              <template slot="title">订单管理</template>
              <el-menu-item index="/rentMessageQuery">订单查询</el-menu-item>
            </el-submenu>         
          
          <el-menu-item index="4">评价管理</el-menu-item>
        
          <el-menu-item index="5">管理人员管理</el-menu-item>
      
          <el-menu-item index="6">个人中心</el-menu-item>
        
          <div id="manager"> 管理员：{{getManager}}</div>
        </el-menu>  
      </div>
    
    <router-view v-if="isRouterAlive"/>
  </div>
</template>

<style>

#manager{
      color: white;
      float:right;
      padding:20px

   }
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color:brown;
}


#nav a {
  font-weight: bold;
  color: #2c3e50;
}

#nav a.router-link-exact-active {
  color: #42b983;
}
</style>


<script>
  export default {
      name:"managerhome",
    provide() {
      return {
        reload: this.reload
      }
    },
    data() {
      return {
        needAuditUserAndParkingSpaceNo:0,
        needAuditUserNo:0,
        needAuditParkingNo:0,
        activeIndex:'1',
        isRouterAlive: true,
      };
    },
    computed:{
      getManager(){
          return localStorage.getItem("manager");
      }        
    },
    methods: {
        reload() {
          this.isRouterAlive = false
          this.$nextTick(() => {
            this.isRouterAlive = true
          })
        },
        toAuditUser(){
            this.$router.push({
                path:"/login"}
            )
            
        },        
        getNeedAuditUserNo(){
          this.$axios.get('/getNeedAuditUserNo',{params:{}})
          .then(resp=>{
              this.needAuditUserNo=resp.data.data;
          })
          .catch(error=>{
              console.log(error)
              this.$message.error('获取需要审核的用户数量发生未知错误');
          })
        },
        getNeedAuditParkingNo(){
          this.$axios.get('/getNeedAuditParkingNo',{params:{}})
          .then(resp=>{
              this.needAuditParkingNo=resp.data.data;
          })
          .catch(error=>{
              console.log(error)
              this.$message.error('获取需要审核的停车场数量发生未知错误');
          })
        },
        getNeedAuditUserAndParkingSpaceNo(){
             this.needAuditUserAndParkingSpaceNo=this.needAuditUserNo+this.needAuditParkingNo;
        },
      
    },
    mounted(){
        this.getNeedAuditUserNo();
        this.getNeedAuditParkingNo();
        // setInterval(this.getNeedAuditUserNo,3000);
        // setInterval(this.getNeedAuditParkingNo,3000);
    },
    updated(){
        this.getNeedAuditUserAndParkingSpaceNo();
    }
  }
</script>
